﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using Gift.WebApp;
using Gift.Model;

namespace WebApp.admin.warehouse
{
    public partial class warehouseGoods : BaseAdmin
    {

        tbWarehouseGoods oWarehouseGoods;
        tbGoods oGoods;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindWarehouse();
                this.BindBuild();
            }
        }

        void BindBuild()
        {
            oGoods = BaseFactory.theGoods.GetModel(int.Parse(base.Request.QueryString["gid"]));
            if (oGoods != null)
            {
                this.lblGoodsName.Text = oGoods.goodsName;
            }
            
        }
        void BindWarehouse()
        {
            DataTable dt = BaseFactory.theWarehouse.GetList("companyId=" + base.Administrator.CompanyId).Tables[0];
            if (dt != null)
            {
                this.ddlWarehouse.DataTextField = "warehouseName";
                this.ddlWarehouse.DataValueField = "id";
                this.ddlWarehouse.DataSource = dt;
                this.ddlWarehouse.DataBind();
            }
            this.ddlWarehouse.Items.Insert(0, new ListItem("请选择仓库", ""));

 
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            oWarehouseGoods = new tbWarehouseGoods();
            oWarehouseGoods.companyId = int.Parse(base.Administrator.CompanyId);
            oWarehouseGoods.creater = int.Parse(base.Administrator.AdminUserId);
            oWarehouseGoods.createTime = DateTime.Now;
            oWarehouseGoods.goodsCount = int.Parse(this.txtCount.Text); 
            oWarehouseGoods.goodsId = int.Parse(Request.QueryString["gid"]);
            oWarehouseGoods.remark = this.txtRemark.Text.Trim();
            oWarehouseGoods.warehouseId = int.Parse(this.ddlWarehouse.SelectedItem.Value);
            oWarehouseGoods.GoodsBatchNo = this.txtGoodsBatchNo.Value.Trim();
            if (BaseFactory.theWarehouseGoods.Add(oWarehouseGoods) > 0)
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加成功！\"); window.location='/admin/goods/goodsList.aspx';</script>");
            }
        }
    }
}